{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "Chapter 07\n",
    "# 使用NumPy计算矩阵乘法\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 定义矩阵 A 和 B\n",
    "A = np.array([[1, 2, 10, 20],\n",
    "              [3, 4, 30, 40]])\n",
    "\n",
    "B = np.array([[1, 3],\n",
    "              [2, 4],\n",
    "              [10, 30],\n",
    "              [20, 40]])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:49:07.318279Z",
     "end_time": "2024-07-03T10:49:07.455234Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 505 1111]\n",
      " [1111 2525]]\n"
     ]
    }
   ],
   "source": [
    "C = A @ B\n",
    "print(C)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:49:23.725187Z",
     "end_time": "2024-07-03T10:49:23.751141Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  10   14  100  140]\n",
      " [  14   20  140  200]\n",
      " [ 100  140 1000 1400]\n",
      " [ 140  200 1400 2000]]\n"
     ]
    }
   ],
   "source": [
    "D = B @ A\n",
    "print(D)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:49:42.000179Z",
     "end_time": "2024-07-03T10:49:42.007191Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
